package com.base.receiver;

import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;

import com.base.util.ClsUtils;

public class BleConnectReceiver extends BroadcastReceiver {
    private static final String ACTION_BLE_ = "android.bluetooth.device.action.PAIRING_REQUEST";

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (TextUtils.equals(ACTION_BLE_, action)) {
            abortBroadcast();//拦截掉广播
            BluetoothDevice btDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            // byte[] pinBytes = BluetoothDevice.convertPinToBytes("1234");
            // device.setPin(pinBytes);
            Log.i("tag11111", "ddd");
            try {
                ClsUtils.setPin(btDevice.getClass(), btDevice, "0000"); // 手机和蓝牙采集器配对
                ClsUtils.createBond(btDevice.getClass(), btDevice);
                ClsUtils.cancelPairingUserInput(btDevice.getClass(), btDevice);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //zhengchangcaozuo
            /*try {
                btDevice.setPairingConfirmation(true);//确认配对
                abortBroadcast();//拦截掉广播
            } catch (Exception e) {
                e.printStackTrace();
            }*/
        }
    }
}
